package com.electromagnetic.industry.software.manage.controller;

import cn.hutool.core.date.DateUtil;
import com.electromagnetic.industry.software.common.annotations.UserOperation;
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
import com.electromagnetic.industry.software.manage.service.FileBackLogService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/data/ed/backup/")
public class FileBackupLogController {

    @Resource
    private FileBackLogService fileBackLogService;

    @RequestMapping(value = "list")
    @UserOperation(value = "查询备份日志", modelName = UserOperationModuleEnum.BACKUP_FILE)
    public ElectromagneticResult<?> list(@RequestParam int pageNum, @RequestParam int pageSize) {
        return fileBackLogService.query(pageNum, pageSize);
    }

    @GetMapping(value = "restore")
    @UserOperation(value = "系统恢复", modelName = UserOperationModuleEnum.BACKUP_FILE)
    public ElectromagneticResult<?> restore() {
        Long maxEndTime = fileBackLogService.restore();
        return ElectromagneticResultUtil.success(DateUtil.date(maxEndTime).toString());
    }
}
